package com.example.jedis.demo;

import java.util.HashSet;
import java.util.Set;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import redis.clients.jedis.*;

/**
 * 描述该类
 *
 * @author <a href="920786312@qq.com">周飞</a>
 * @class: Demo01
 * @date 2022/2/2 15:23
 * @Verson 1.0 -2022/2/2 15:23
 * @see
 */
public class Demo04 {
    
    public static void main(String[] args) {
        
        Set<HostAndPort> set = new HashSet<HostAndPort>();
        set.add(new HostAndPort("192.168.187.139", 7000));
        set.add(new HostAndPort("192.168.187.139", 7001));
        set.add(new HostAndPort("192.168.187.139", 7002));
        set.add(new HostAndPort("192.168.187.139", 7003));
        set.add(new HostAndPort("192.168.187.139", 7004));
        set.add(new HostAndPort("192.168.187.139", 7005));
        
        int connectionTimeout = 2000;
        int soTimeout = 2000;
        int maxAttempts = 5;
        // redis认证密码
        String password = "123456";
        
        // 连接
        JedisCluster jedisCluster = new JedisCluster(set, connectionTimeout, soTimeout, maxAttempts, password,
                new GenericObjectPoolConfig());
        
        jedisCluster.set("k1", "v1");
        System.out.println("集群测试:" + jedisCluster.get("k1"));
        jedisCluster.close();
        
    }
    
}